<#include "/WEB-INF/views/admin/common/layout/__mainlayout.html">
<#assign navLink='admin:sys:config:save' />
<#assign pageCss>
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
</#assign>
<#assign pageScript>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	var pullfiles = function() {
		// love the query selector
		var fileInput = document.querySelector("#file");
		var files = fileInput.files;
		// cache files.length 
		var fl = files.length;
		var i = 0;

		while (i < fl) {
			// localize file var in the loop
			var file = files[i];
			if (checkSuffix(file.name)) {
				$("#fileName").html(file.name);
				i++;
			} else {
				layer.msg('Please upload the correct apk file！', {
					icon : 5
				});
				i++;
			}
		}
	}
	document.querySelector("#file").onchange = pullfiles;

	function checkSuffix(str) {
		var strRegex = "(.apk)$"
		var re = new RegExp(strRegex);
		if (re.test(str.toLowerCase())) {
			return true;
		} else {
			return false;
		}
	}
	function validate(formData, jqForm, options) {
		return true;
	}
	
	$("#frm").validationEngine('attach', {
		promptPosition : 'topLeft',
		scroll : false
	});
  	$("#frm").ajaxForm(
			{
				dataType : "json",
				beforeSubmit : validate,
				success : function(result) {
					layer.closeAll('loading');
					if (result.isSuccess) {
						layer.msg(result.msg, {
							icon : 1,
							time : 1000,
							end : function() {
								//信息提示完成后关闭表单窗口
								var index = parent.layer
										.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭  
							}
						});
					} else {
						layer.alert(result.msg, {
							icon : 5
						});
					}
				},
				error : function(ret) {

				}
			});
});


</script>
</#assign>
<@mainlayout>
<div class="row-content am-cf">
<div class="row">
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
<form class="am-form tpl-form-border-form" id="frm" method="post"
					enctype="multipart/form-data"
					action="${ctx}/admin/sys/config/upload/">
<input type="hidden" name="config.id" id="config.id" value="${config.id!}">

  <fieldset>
    <legend>system base config</legend>

    <div class="am-form-group">
      <label for="domain">domain</label>
      <input type="url" class="tpl-form-input validate[required,custom[url]]" name="config.domain_name" id="domain" value="${config.domain_name!}" placeholder="please enter the domain name">
    </div>

    <div class="am-form-group">
      <label for="new_app_version">new app version</label>
      <input type="text" class="tpl-form-input validate[required,custom[price]]" name="config.new_appversion" id="new_app_version" value="${config.new_appversion!}" placeholder="please enter the new app version">
    </div>

   <div class="am-form-group am-form-file">
						<div>
							<button type="button" class="am-btn am-btn-default am-btn-sm">
								<i class="am-icon-cloud-upload"></i> Select the file to upload
							</button>
							<p id="fileName">${config.update_url}</p>
						</div>
						<input type="file" id="file" name="file">
					</div>

    <p><button type="submit" class="am-btn am-btn-default">submit</button></p>
  </fieldset>
</form>
</div>
</div>
</div>
</@mainlayout>

